﻿angular.module('Caltech').directive('yearlyReport', function () {
    'use strict';

    var controller = function ($scope, Restangular) {

        var currentYear = (new Date).getFullYear();

        $scope.currentYearlyReportDate = new Date;
        $scope.fromYear = currentYear - 2;
        $scope.toYear = currentYear;

        $scope.yearlyothers = {
            other1: "Other 1",
            other2: "Other 2",
            other3: "Other 3",
            other4: "Other 4",
            other5: "Other 5"
        };

        $scope.getYearlyReports = function () {

            if ($scope.fromYear >= $scope.toYear) {
                return;
            }

            Restangular.all('reports').customGETLIST(
           'yearlyreports',
           {
               fromYear: $scope.fromYear,
               toYear: $scope.toYear
           }).then(function (reports) {
               $scope.yearlyReports = reports || {};
           });
        };

        $scope.getYearlyReports();
    };

    return {
        restrict: 'E',
        replace: true,
        transclude: true,
        templateUrl: 'Scripts/app/views/_partials/yearlyReport.html',
        controller: controller
    }
});
